import 'package:flutter/material.dart';
import 'package:tetris/material/briks.dart';
import 'package:tetris/material/material.dart';
import '../MyConfig.dart';
import 'PlayerPanel.dart';
import 'StatusPanel.dart';


/// 最中间那个游戏视图
class Screen extends StatelessWidget {
  final double width;

  const Screen({Key key, @required this.width}) : super(key: key);

  // todo 命名构造函数
  // Screen.fromHeight(double height) : this(width: ((height - 6) / 2 + 6) / 0.6);

  @override
  Widget build(BuildContext context) {
    //play panel need 60%
    final playerPanelWidth = width * 0.6;

    var view1 = SizedBox(
      height: (playerPanelWidth - 6) * 2 + 6,
      width: width,
      child: Container(
        // todo ，这个颜色设置比较逼真，不要设置其他颜色
        color: SCREEN_BACKGROUND,
        child: GameMaterial(
          child: BrikSize(
            size: getBrikSizeForScreenWidth(playerPanelWidth),
            child: Row(
              children: <Widget>[
                PlayerPanel(width: playerPanelWidth),
                // 右侧状态栏
                SizedBox(
                  width: width - playerPanelWidth,
                  child: StatusPanel(),
                )
              ],
            ),
          ),
        ),
      ),
    );

    // var shakeView =Shake(
    //   shake: GameState.of(context).states == GameStates.drop,
    //   child: view1,
    // ) ;

    return view1 ;
  }
}

// class Shake extends StatefulWidget {
//   final Widget child;
//
//   ///true to shake screen vertically
//   final bool shake;
//
//   const Shake({Key key, @required this.child, @required this.shake})  : super(key: key);
//
//   @override
//   _ShakeState createState() => _ShakeState();
// }

///摇晃屏幕
// class _ShakeState extends State<Shake> with TickerProviderStateMixin {
//   AnimationController _controller;
//
//   @override
//   void initState() {
//     _controller =
//         AnimationController(vsync: this, duration: Duration(milliseconds: 150))
//           ..addListener(() {
//             setState(() {});
//           });
//     super.initState();
//   }
//
//   @override
//   void didUpdateWidget(Shake oldWidget) {
//     super.didUpdateWidget(oldWidget);
//     if (widget.shake) {
//       _controller.forward(from: 0);
//     }
//   }
//
//   @override
//   void dispose() {
//     _controller.dispose();
//     super.dispose();
//   }
//
//   v.Vector3 _getTranslation() {
//     double progress = _controller.value;
//     double offset = sin(progress * pi) * 1.5;
//     return v.Vector3(0, offset, 0.0);
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return Transform(
//       transform: Matrix4.translation(_getTranslation()),
//       child: widget.child,
//     );
//   }
// }
